package com.heima.wemedia.controller.v1;

import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.constants.admin.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dtos.NewsAuthDTO;
import com.heima.model.wemedia.dtos.WmNewsDTO;
import com.heima.model.wemedia.dtos.WmNewsPageReqDTO;
import com.heima.model.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "自媒体文章管理API",tags = "自媒体文章管理API")
@RestController
@RequestMapping("/api/v1/news")
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;
    @ApiOperation("根据条件查询文章列表")
    @PostMapping("/list")
    public ResponseResult findAll(@RequestBody WmNewsPageReqDTO wmNewsPageReqDto){
        return wmNewsService.findList(wmNewsPageReqDto);
    }

    @PostMapping("/submit")
    @ApiOperation("自媒体文章-发布、修改、保存草稿")
    public ResponseResult submitNews(@RequestBody WmNewsDTO dto){
        return wmNewsService.submitNews(dto);
    }
    @ApiOperation(value = "根据id查询自媒体文章")
    @GetMapping("/one/{id}")
    public ResponseResult findWmNewsById(@PathVariable("id") Integer id) {
        return wmNewsService.findWmNewsById(id);
    }

    @GetMapping("/del_news/{id}")
    @ApiOperation(value = "根据id删除自媒体文章")
    public ResponseResult delNews(@PathVariable("id") Integer id) {
        return wmNewsService.deleteById(id);
    }
    @PostMapping("/down_or_up")
    @ApiOperation(value = "自媒体文章上架或下架",notes = "enable 上架: 1 下架: 0")
    public ResponseResult downOrUp(@RequestBody WmNewsDTO dto) {
        return wmNewsService.downOrUp(dto);
    }

    @PostMapping("/list_vo")
    @ApiOperation(value = "查询自媒体文章列表",notes = "返回值带作者信息，主要运营管理端调用")
    public ResponseResult findList(@RequestBody NewsAuthDTO dto){
        return wmNewsService.findList(dto);
    }
    @GetMapping("/one_vo/{id}")
    @ApiOperation(value = "查询自媒体文章详情",notes = "返回值带作者信息，主要运营管理端调用")
    public ResponseResult findOneVo(@PathVariable("id") Integer id){
        return wmNewsService.findOneVo(id);
    }
    @PostMapping("/auth_pass")
    @ApiOperation("人工审核通过 状态:4")
    public ResponseResult anthPass(@RequestBody NewsAuthDTO dto){
        return wmNewsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_PASS,dto);
    }
    @PostMapping("/auth_fail")
    @ApiOperation("人工审核未通过 状态:2")
    public ResponseResult anthFail(@RequestBody NewsAuthDTO dto){
        return wmNewsService.updateStatus(WemediaConstants.WM_NEWS_AUTH_FAIL,dto);
    }
    @ApiOperation("根据id修改自媒体文章")
    @PutMapping("/update")
    public ResponseResult updateWmNews(@RequestBody WmNews wmNews) {
        wmNewsService.updateById(wmNews);
        return ResponseResult.okResult();
    }
}
